/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import controllers.Peliculas;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import models.enums.TipoClasificacion;
import models.enums.TipoGenero;

/**
 *
 * @author kevin_000
 */
public class AgregarPeliculas extends javax.swing.JFrame {

    Peliculas p;

    /**
     * Creates new form AgregarPeliculas
     */
    public AgregarPeliculas() {
        initComponents();
        setSize(900, 500);
        setLocationRelativeTo(null);
        p = new Peliculas();
        cmbClasificacion.removeAllItems();
        cmbGenero.removeAllItems();
        fillComboTipoClasificacion();
        fillComboTipoGenero();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lblImagen = new javax.swing.JLabel();
        txtDuracion = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        txtTitulo = new javax.swing.JTextField();
        cmbGenero = new javax.swing.JComboBox();
        lblPoster = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        cmbClasificacion = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Agregar Nueva Pelicula");
        getContentPane().setLayout(null);

        jLabel3.setFont(new java.awt.Font("Rockwell", 3, 48)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("AGREGAR NUEVA PELICULA");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(70, 10, 700, 50);

        jLabel4.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Clasificación");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(20, 280, 220, 40);

        jLabel5.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Poster");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(20, 330, 220, 40);

        jLabel6.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Género");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(20, 230, 220, 40);

        jLabel7.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setText("Duración");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(20, 180, 220, 40);

        lblImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/NOIMAGEN1.jpg"))); // NOI18N
        getContentPane().add(lblImagen);
        lblImagen.setBounds(590, 90, 260, 350);

        txtDuracion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDuracionActionPerformed(evt);
            }
        });
        getContentPane().add(txtDuracion);
        txtDuracion.setBounds(280, 190, 280, 30);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 20.png"))); // NOI18N
        jButton3.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 20 Rollover.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton3);
        jButton3.setBounds(200, 390, 180, 60);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 21.png"))); // NOI18N
        jButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 21 Rollover.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(390, 390, 180, 60);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 23.png"))); // NOI18N
        jButton2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 23 Rollover.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(10, 380, 160, 50);
        getContentPane().add(txtTitulo);
        txtTitulo.setBounds(280, 140, 280, 30);

        cmbGenero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        getContentPane().add(cmbGenero);
        cmbGenero.setBounds(280, 240, 280, 20);
        getContentPane().add(lblPoster);
        lblPoster.setBounds(280, 340, 270, 20);

        jLabel10.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setText("Titulo");
        getContentPane().add(jLabel10);
        jLabel10.setBounds(20, 130, 220, 40);

        cmbClasificacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbClasificacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbClasificacionActionPerformed(evt);
            }
        });
        getContentPane().add(cmbClasificacion);
        cmbClasificacion.setBounds(280, 290, 280, 20);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/colorful_bokeh-1920x1200.jpg"))); // NOI18N
        getContentPane().add(jLabel2);
        jLabel2.setBounds(0, -10, 894, 558);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        p.agregarPelicula(txtTitulo.getText(),
                Integer.parseInt(txtDuracion.getText()),
                cmbGenero.getSelectedItem().toString(),
                cmbClasificacion.getSelectedItem().toString(),
                lblPoster.getText());
        
        
        JOptionPane.showMessageDialog(rootPane, "PeliculaAgregada con Exito");
        
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void cmbClasificacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbClasificacionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbClasificacionActionPerformed

    private void txtDuracionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDuracionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDuracionActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        String path = p.getPoster();
        lblPoster.setText(path);
        lblImagen.setIcon(new ImageIcon(path));

    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AgregarPeliculas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AgregarPeliculas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AgregarPeliculas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AgregarPeliculas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AgregarPeliculas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbClasificacion;
    private javax.swing.JComboBox cmbGenero;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel lblImagen;
    private javax.swing.JLabel lblPoster;
    private javax.swing.JTextField txtDuracion;
    private javax.swing.JTextField txtTitulo;
    // End of variables declaration//GEN-END:variables

    private void fillComboTipoClasificacion() {
        ArrayList<TipoClasificacion> tipoClasificaciones = (ArrayList<TipoClasificacion>) p.getClasificaciones();
        tipoClasificaciones.stream().forEach((tipoClasificacion) -> {
            cmbClasificacion.addItem(tipoClasificacion.toString());
        });

    }

    private void fillComboTipoGenero() {
        ArrayList<TipoGenero> tipoGeneros = (ArrayList<TipoGenero>) p.getGeneros();
        tipoGeneros.stream().forEach((tipoGenero) -> {
            cmbGenero.addItem(tipoGenero.toString());
        });
    }

}
